package com.lazybones.base.engineer.common.res;

import com.lazybones.base.engineer.common.enums.StatusEnum;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class ResultRes implements Serializable {
    private Boolean success;
    private Integer code;
    private String message;
    private   Map<String,Object> data=new HashMap<String,Object>();
    private ResultRes(){}

/**
    Description: 通用返回成功
    Return: rs;
**/
    public static ResultRes ok(){
        ResultRes rs = new ResultRes();
        rs.setCode(StatusEnum.SUCCESS.getCode());
        rs.setMessage(StatusEnum.SUCCESS.getMessage());
        rs.setSuccess(StatusEnum.SUCCESS.getSuccess());
        return rs;
    }
/**
    Description: 通用失败返回
    Return:
**/
    public static ResultRes error(){
        ResultRes rs = new ResultRes();
        rs.setSuccess(StatusEnum.UNKNOWN_ERROR.getSuccess());
        rs.setCode(StatusEnum.UNKNOWN_ERROR.getCode());
        rs.setMessage(StatusEnum.UNKNOWN_ERROR.getMessage());
        return  rs;
    }
/**
    Parameters: result —
    Return:
 **/
    public  static ResultRes setResult(StatusEnum result){
        ResultRes rs = new ResultRes();
        rs.setSuccess(result.getSuccess());
        rs.setMessage(result.getMessage());
        rs.setCode(result.getCode());
        return rs;
    }
/**
    Descrition: 使用链式编程，返回类本身
    Parameters: map —
    Return:
  **/
    public ResultRes data(Map<String,Object> map){
        this.setData(map);
        return  this;
    }
   // 通用data
    public ResultRes data(String key,Object value){
        this.data.put(key,value);
        return this;
    }
   // 自定义状态message
    public ResultRes message(String message){
        this.setMessage(message);
        return this;
    }
    public ResultRes code(Integer code){
        this.setCode(code);
        return this;
    }
    public ResultRes success(Boolean success){
        this.setSuccess(success);
        return this;
    }

/**
    Parameters:
    success —
    code —
    message —
**/
    public ResultRes(Boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
        data = new HashMap<String,Object>();
    }


    @Override
    public String toString() {
        return "ResultRes{" +
                "success=" + success +
                ", code=" + code +
                ", message='" + message + '\'' +
                '}';
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

}
